<!DOCTYPE html>
<!--suppress ALL-->
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <base th:href="@{/}"><!-- 不用base就使用th:src="@{/js/jquery.min.js} -->
    <meta charset="UTF-8">
    <title>购物车页面</title>
    <link rel="stylesheet" href="css/bootstrap.min.css"/>
    <script src="js/jquery.min.js"></script>
</head>
<body>
<div th:include="user/header"></div>
<div class="container">
    <div class="panel panel-primary">
        <div class="panel-heading">
            <h3 class="panel-title">购物车列表</h3>
        </div>
        <div class="panel-body">
            <div class="table table-responsive">
                <table class="table table-bordered table-hover">
                    <tbody class="text-center">
                    <tr>
                        <th>商品信息</th>
                        <th>商品名称</th>
                        <th>单价（元）</th>
                        <th>数量</th>
                        <th>小计</th>
                        <th>操作</th>
                    </tr>
                    <tr th:each="cart:${cartList}">
                        <td>
                            <a th:href="'goodsDetail?id=' + ${cart.goods.id}">
                                <img th:src="'images/' + ${cart.goods.gpicture}"
                                     style="height: 50px; width: 50px; display: block;">
                            </a>
                        </td>
                        <td th:text="${cart.goods.gname}"></td>
                        <td th:text="${cart.goods.grprice}"></td>
                        <td th:text="${cart.num}"></td>
                        <td th:text="${cart.totalPrice}"></td>
                        <td>
                            <a th:href="'javascript:deleteCart('+${cart.cartId}+')'">删除</a>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="5">
                            <font style="color: #a60401; font-size: 13px; font-weight: bold; letter-spacing: 0px;">
                                <!--								购物金额总计(不含运费) ￥&nbsp;<span th:text="${total}"></span>元-->
                            </font>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="5">
                            <a href="javascript:clearCart()">清空购物车</a>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="5">
                            <a href="cart/selectCart?act=toCount">去结算</a>
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
</body>

<script>
    function deleteCart(cartId) {

        var url = "/cart/deleteOne"
        $.post(url, {"cartId": cartId}, function (data) {
            if (data.state == 200) {
                alert(data.message);
                location.href = "/cart/cartList"
            } else {
                alert(data.message);
            }
        }, "json");
    }

    function clearCart() {
        var url = "/cart/deleteAll"
        $.post(url, function (data) {
            if (data.state == 200) {
                alert(data.message);
                location.href = "/cart/cartList"
            } else {
                alert(data.message);
            }
        }, "json");
    }
</script>
</html>